package online.flowerinsnow.tcpudpclient.gui.tcp

import javax.swing.*

class TCPTab : JPanel(null) {
    val ping = JButton("Ping")
    val connect = JButton("连接")
    val settings = JButton("IP")
    val send = JButton("发送")
    val disconnect = JButton("断开")

    val log = JTextArea()

    private val center = JScrollPane(log)

    init {
        initComps()
        addListener()
    }

    private fun initComps() {
        ping.setBounds(0, 300, 94, 30)
        add(ping)
        ping.isEnabled = false

        connect.setBounds(94, 300, 94, 30)
        add(connect)
        connect.isEnabled = false

        settings.setBounds(188, 300, 94, 30)
        add(settings)

        send.setBounds(282, 300, 94, 30)
        add(send)
        send.isEnabled = false

        disconnect.setBounds(376, 300, 94, 30)
        add(disconnect)
        disconnect.isEnabled = false

        log.isEditable = false
        center.setBounds(0, 0, 470, 300)
        add(center)
    }

    private fun addListener() {
        settings.addActionListener {
            setAllDisable()

            TCPIPSettingsGUI(this)
        }
    }

    private fun setAllDisable() {
        ping.isEnabled = false
        connect.isEnabled = false
        settings.isEnabled = false
        send.isEnabled = false
        disconnect.isEnabled = false
    }
}